##使用curve_fit

import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit



def fit(x, y,argsStr='a,b,c,d',funcstr='a * x ** 3 + b * x ** 2 + c * x + d'):
    # 非线性最小二乘法拟合
    st='''
def func(x, %s):
    return %s
    '''%(argsStr,funcstr)
    print(st)
    exec(st,globals())
    popt, pcov = curve_fit(func, x, y)
    # 获取popt里面是拟合系数
    yvals = func(x, *popt)
    # 拟合，将数组作为函数的参数进行传入。
    return popt, pcov, yvals
def loadVariables():
    import novalmber
    path=novalmber.getUserDataPath(debug=False)# 通过网络直接远程获取。
    a=__file__.split('apps')[0]

    import os
    import pickle
    path=os.path.join(path,'pluginfiles/scientificshell')
    print(path)
    varDic={}
    
    dirList=os.listdir(path)
    print(dirList)
    for file in dirList:
        if file.endswith('.pkl'):
            sl=file.split('.')
            
            try:
                f=open(os.path.join(path,file),'rb')
                name=sl[0]
                varDic[name]=pickle.load(f)
                f.close()
            except:
                import traceback
                traceback.print_exc()
    print(varDic)
    return varDic     

if __name__ == '__main__':
    
    vd=loadVariables()
    print(vd)

